<?php
namespace Hilaoyu\ComputeCloudClient\Api;

use Hilaoyu\ComputeCloudClient\ctyun\CtyunCLient;
use Hilaoyu\ComputeCloudClient\ctyun\CtyunClientEcs;
use Hilaoyu\ComputeCloudClient\ctyun\CtyunClientIms;
use Hilaoyu\ComputeCloudClient\ctyun\CtyunClientVpc;
use Hilaoyu\ComputeCloudClient\CtyunApi;
use Hilaoyu\Utils\UtilArr;
use Hilaoyu\Utils\Traits\ErrorsTrait;

class CtyunApiBase
{
    use ErrorsTrait;

    /**
     * @var CtyunCLient | CtyunClientVpc | CtyunClientEcs
     */
    protected $client;
    protected $api;
    protected $regionId;

    protected $_clientVpc;
    protected $_clientEcs;
    protected $_clientIms;
    public function __construct(CtyunCLient $client ,CtyunApi $api,$regionId=''){
        $this->client = $client;
        $this->api = $api;
        $this->regionId = trim($regionId);
    }

    protected function getRegionId($regionId=''){
        $regionId = trim($regionId);
        if(!$regionId){
            $regionId = $this->regionId;
        }
        return $regionId;
    }

    public function getClient(){
        return $this->client;
    }

    /**
     * @return CtyunClientVpc
     */
    public function clientVpc(){
        if (!$this->_clientVpc) {
            $this->_clientVpc = $this->api->vpc($this->getRegionId())->getClient();
        }
        return $this->_clientVpc;
    }

    /**
     * @return CtyunClientEcs
     */
    public function clientEcs(){
        if (!$this->_clientEcs) {
            $this->_clientEcs = $this->api->ecs($this->getRegionId())->getClient();
        }
        return $this->_clientEcs;
    }

    /**
     * @return CtyunClientIms
     */
    public function clientIms(){
        if (!$this->_clientIms) {
            $this->_clientIms = $this->api->ims($this->getRegionId())->getClient();
        }
        return $this->_clientIms;
    }




}
